import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Random;

public class Sender implements Runnable {

	private Message msg;

	public Sender(Message msg) {
		this.msg = msg;
		new Thread(this, msg.getSenderProcess() + " action").start();
	}

	@Override
	public void run() {
			for (int i = 0; i < msg.getReceipients().length; i++) {
				int r = msg.getReceipients()[i];
				try(Socket client = new Socket(ProcessManager.serverName,
						ProcessManager.ports[r])) {
				OutputStream outToServer = client.getOutputStream();
				ObjectOutputStream out = new ObjectOutputStream(outToServer);
//				if (msg instanceof MarkerMessage) {
//					
//				}
				out.writeObject(msg);
				out.flush();
				} catch (IOException e) {
					System.out.println("Sender: No server found");
				}
			}
	}
}
